package com.alcatel_lucent.osp.model;

import org.apache.struts2.json.annotations.JSON;

import javax.persistence.*;
import java.util.Collection;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: guoshunw
 * Date: 13-8-23
 * Time: 下午6:08
 * To change this template use File | Settings | File Templates.
 */

@Entity
@Table(name = "COMMENT")
public class Comment extends BaseEntity {
    private String content;
    private User creator;
    private Date createTime;
    private Request request;

    private Collection<Attachment> attachments;


    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdCommentGenerator")
    @SequenceGenerator(name = "IdCommentGenerator", sequenceName = "ID_COMMENT", allocationSize = 20)
    @Override
    public Long getId() {
        return super.getId();
    }


    @Column(name = "CONTENT")
    @Lob
    @org.hibernate.annotations.Type(type = "text")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @ManyToOne
    @JoinColumn(name = "CREATOR_CSL")
    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    @JSON(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "CREATE_TIME")
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "COMMENT_ID")
    public Collection<Attachment> getAttachments() {
        return attachments;
    }

    public void setAttachments(Collection<Attachment> attachments) {
        this.attachments = attachments;
    }


    @ManyToOne
    @JoinColumn(name = "REQUEST_ID")
    public Request getRequest() {
        return request;
    }


    public void setRequest(Request request) {
        this.request = request;
    }
}
